﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using mBlogAPI.Schema;
using mBlogAPI.BL;
using mBlogAPI.Utils;

namespace MyDesktopMicroBlog
{
    /// <summary>
    /// Interaction logic for StatusManage.xaml
    /// </summary>
    public partial class StatusManage : BaseWindow
    {
        public string Operation { get; set; }
        public string StatusText { get; set; }
        public string User { get; set; }
        public string StatusID { get; set; }
        public Status Status{ 
            set
            {
                if (this.StatusType == OperateStatusType.RepliedStatus)
                {
                    this.StatusText = value.InReplyToStatusText;
                    this.User = value.InReplyToScreenName + ":";
                    this.StatusID = value.InReplyToStatusId;
                }
                else
                {
                    this.StatusText = value.Text;
                    this.User = value.User.ScreenName + ":";
                    this.StatusID = value.Id;
                }
            }
        }

        public OperateStatusType StatusType { get; set; }
        public StatusManage()
        {
            InitializeComponent();
            txtContent.Focus();
            this.DataContext = this;
        }

        private void Close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnPublish_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                StatusesBL.ReplyToStatus(txtContent.Text.Trim(), int.Parse(StatusID));

                this.Close();
            }
            catch(Exception ex)
            {
                LogHelper.LogError(ex);
                MessageHelper.ShowAndHideMessage("抱歉，回复失败了...");
            }
        }
    }
}
